setlocal enableextensions enabledelayedexpansion
set appcmd="%windir%\system32\inetsrv\appcmd"
set hosts="%windir%\system32\drivers\etc\hosts"

%appcmd% set config -section:webFarms /-"[name='localfarm']" /commit:apphost
%appcmd% set config -section:webFarms /+"[name='localfarm']" /commit:apphost
%appcmd% set config -section:webFarms /[name='localfarm'].applicationRequestRouting.protocol.cache.enabled:false
%appcmd% set config -section:webFarms /[name='localfarm'].applicationRequestRouting.healthCheck.url:"http://localhost"
%appcmd% set config -section:webFarms /[name='localfarm'].applicationRequestRouting.healthCheck.timeout:"00:00:02"
%appcmd% set config -section:webFarms /[name='localfarm'].applicationRequestRouting.loadBalancing.algorithm:WeightedRoundRobin

del %hosts%
for /l %%n in (0, 1, 7) do (
    echo 127.0.0.1 localhost%%n >> %hosts%
    set /a port=9000+%%n
    %appcmd% set config -section:webFarms /+"[name='localfarm'].[address='localhost%%n']" /commit:apphost
    %appcmd% set config -section:webFarms /[name='localfarm'].[address='localhost%%n'].applicationRequestRouting.httpPort:!port!
)